/**
 * 账户页面
 */
import {
  getAccountInfo,
} from '/common/api';

Page({
  data: {
    accountInfo: {},
    nickName: '',
    avatar: '',
  },
  onLoad() {
    my.getAuthUserInfo({
      success: (res) => {
        const { nickName, avatar } = res;
        this.setData({
          nickName,
          avatar,
        });
      },
    });
  },
  onShow() {
    getAccountInfo()
      .then(({ data: res}) => {
        if (res.message === 'success') {
          this.setData({
            accountInfo: res.data,
          });
        } else {
          const { data: content } = res;
          my.showToast({
            type: 'fail',
            content,
          });
        }
      }).catch((err) => {
        console.log(err);
      });
  },
});
